package SAXParser;

import java.net.URL;
import java.util.ArrayList;
import java.util.Set;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class NaverOpenAPI {
	
	private static ArrayList<RankPost> posts = new ArrayList<RankPost>();
	
	public static void main(String[] args) {
		getRank();
	}
	
	public static void getRank() {
		NaverRank dh = null;
		String naver = "http://openapi.naver.com/search?key=041d0a656b29e0b0df2eb2a06ea605ac&query=nexearch&target=rank";	
		try{
			
			SAXParserFactory saxPF = SAXParserFactory.newInstance();
			SAXParser saxP = saxPF.newSAXParser();
			XMLReader xmlR = saxP.getXMLReader();
			URL url = new URL(naver);
			NaverRank myRankHandler = new NaverRank();
			xmlR.setContentHandler(myRankHandler);
			xmlR.parse(new InputSource(url.openStream()));
			
			posts = myRankHandler.getPost();
			
			for(RankPost arr:posts) {
				System.out.println(arr);
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}	

}
